#pragma once

#include <vector>
#include <map>

using namespace std;
struct Node
{
    int val;
    vector<Node *> neighbors;
    Node()
    {
        val = 0;
        neighbors = vector<Node *>();
    }
    Node(int _val)
    {
        val = _val;
        neighbors = vector<Node *>();
    }
    Node(int _val, vector<Node *> _neighbors)
    {
        val = _val;
        neighbors = _neighbors;
    }
};

Node *CreateNodeFromLinkedIDList(vector<vector<int>> &list)
{
    map<int, Node *> nodeMap;
    for (int i = 0; i < list.size(); i++)
    {
        int c1 = list[i][0];
        int c2 = list[i][1];
        if (nodeMap.find(c1) == nodeMap.end())
        {
            nodeMap[c1] = new Node(c1);
        }
        if (nodeMap.find(c2) == nodeMap.end())
        {
            nodeMap[c2] = new Node(c2);
        }
        nodeMap[c1]->neighbors.push_back(nodeMap[c2]);
        nodeMap[c2]->neighbors.push_back(nodeMap[c1]);
    }
    return nodeMap.begin() == nodeMap.end() ? nullptr : nodeMap.begin()->second;
}